import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { initMenu } from "./utils/menu"
import { deleteRequest, postKeyValueRequest, postRequest, putRequest, getRequest } from './utils/api'
import 'font-awesome/css/font-awesome.min.css'
Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.prototype.postRequest = postRequest;
Vue.prototype.postKeyValueRequest = postKeyValueRequest;
Vue.prototype.putRequest = putRequest;
Vue.prototype.deleteRequest = deleteRequest;
Vue.prototype.getRequest = getRequest;

router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next();
  } else {
    //当页面没有登陆时，直接跳转到登陆页面，登陆完成后直接跳转到原先到页面
    if (window.sessionStorage.getItem("user")) {
      initMenu(router, store);
      next();
    } else {
      //实现登陆完成后直接跳转到用户访问到页面，即之前访问到页面
      next('/?redirect=' + to.path);
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
